package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Stock;
import cn.wolfcode.crm.mapper.StockMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class StockServiceImpl implements IStockService {

    @Autowired
    private StockMapper mapper;

    public void insert(Stock entity) {
        entity.setInputTime(new Date());
        entity.setInputUser(new Employee());//设置当前登录的人为输入的人
        mapper.insert(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void update(Stock entity) {
        entity.setUpdateTime(new Date());
        entity.setUpdateUser(new Employee());//设置当前登录账户为盘点的人
        mapper.updateByPrimaryKey(entity);
    }

    public Stock get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<Stock> list() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = mapper.queryForCount(qo);
        List<Stock> rows = mapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    public void productNumberUpdate(String productName, BigDecimal salecount) {
        mapper.productNumberUpdate(productName,salecount);
    }

    public List<Stock> productNumberSelect(String productName) {
      return mapper.productNumberSelect(productName);
    }
}
